//
//  LXFoodRangeVC.m
//  bgms_d
//
//  Created by Mountain on 9/3/2019.
//  Copyright © 2019 lachesis-zhu. All rights reserved.
//

#import "LXFoodRangeVC.h"
#import "LXFoodViewController.h"
#import "LXFoodItem.h"
#import "LXDevSettingModel.h"

@interface LXFoodRangeVC ()

@end

@implementation LXFoodRangeVC

#pragma mark -  public method

#pragma mark -  life cycle
- (void)dealloc
{
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initializationData];
    [self addNotification];
    
    [self loadUI];
    
    [self loadViewDatas];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = YES;
}

- (void)viewDidAppear:(BOOL)animated
{
    
}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
}
#pragma mark -  over write

#pragma mark -  setter & getter

#pragma mark -  private method
- (void)initializationData
{
    
}

- (void)loadUI
{
    self.view.backgroundColor = kAppBackgroundColor;
    [self buildNavi];
    
    [self.tempBoardView drawAroundViewWithLocation:DrawTop color:kAppLinesColor insets:UIEdgeInsetsMake(0, 0, -0.5, 0)];
    [self.highBoardView drawAroundViewWithLocation:DrawTop color:kAppLinesColor insets:UIEdgeInsetsMake(0, 0, -0.5, 0)];
    [self.lowBoardView drawAroundViewWithLocation:DrawTop color:kAppLinesColor insets:UIEdgeInsetsMake(0, 0, -0.5, 0)];
    self.tempAddText.borderStyle = UITextBorderStyleNone;
    self.tempMusText.borderStyle = UITextBorderStyleNone;
    self.nameText.borderStyle = UITextBorderStyleNone;
    self.tempAddText.keyboardType = UIKeyboardTypePhonePad;
    self.tempMusText.keyboardType = UIKeyboardTypePhonePad;
    self.tempTypeLabel1.text = [LXDevSettingModel shareSettingModel].tempUnitF ? @"°F" : @"°C";
    self.tempTypeLabel2.text = [LXDevSettingModel shareSettingModel].tempUnitF ? @"°F" : @"°C";
}

- (void)loadViewDatas
{
    
}

- (void)buildNavi
{
    [self.navigationView drawAroundViewWithLocation:DrawBottom color:kAppLinesColor insets:UIEdgeInsetsMake(-0.5, 0, 0, 0)];
    if (IPHONE_X) {
        self.naviHeight.constant = 66 + 22;
    }
//    UIButton *editBtn = [[UIButton alloc] init];
//    [editBtn setImage:[UIImage imageNamed:@"okIcon"] forState:UIControlStateNormal];
//    [editBtn addTarget:self action:@selector(okDown:) forControlEvents:UIControlEventTouchUpInside];
//    UIBarButtonItem *editBar = [[UIBarButtonItem alloc] initWithCustomView:editBtn];
//    self.navigationItem.rightBarButtonItem = editBar;
}

#pragma mark -  notification
- (void)addNotification
{
    
}

#pragma mark -  network


#pragma mark -  event handle
- (IBAction)okDown:(UIButton *)sender
{
    if ([self.nameText.text isEqualToString:@""]) {
        [EasyTextView showErrorText:NSLocalizedString(@"TheNameNull", nil)];
        return;
    }
    if ([self.tempAddText.text integerValue] < [[[LXDevSettingModel shareSettingModel] tempCTempF:@"0"] integerValue] || [self.tempAddText.text integerValue] > [[[LXDevSettingModel shareSettingModel] tempCTempF:@"300"] integerValue]) {
        [EasyTextView showErrorText:NSLocalizedString(@"TemperatureOutSTandard", nil)];
        return;
    }
    if ([self.tempMusText.text integerValue] < [[[LXDevSettingModel shareSettingModel] tempCTempF:@"0"] integerValue] || [self.tempMusText.text integerValue] > [[[LXDevSettingModel shareSettingModel] tempCTempF:@"300"] integerValue]) {
        [EasyTextView showErrorText:NSLocalizedString(@"TemperatureOutSTandard", nil)];
        return;
    }
    if ([self.tempAddText.text integerValue] <= [self.tempMusText.text integerValue]) {
        [EasyTextView showErrorText:NSLocalizedString(@"TheMinTemperatureLess", nil)];
        return;
    }
    LXFoodItem *item = [[LXFoodItem alloc] init];
    item.name = self.nameText.text;
    item.setNum = [[LXDevSettingModel shareSettingModel] tempFTempC:self.tempAddText.text];
    item.selected = NO;
    item.image = @"other";
    item.cookedLevel = @(6);
    item.minNum = [[LXDevSettingModel shareSettingModel] tempFTempC:self.tempMusText.text];
    item.unit = [LXDevSettingModel shareSettingModel].tempUnitF ? @"°F" : @"°C";
    item.show = NO;
    item.rangeTemp = YES;
    LXFoodViewController *foodVC =  [self.navigationController.viewControllers objectAtIndex:self.navigationController.viewControllers.count - 2];
    foodVC.addItem = item;
    [self.navigationController popViewControllerAnimated:YES];
}

- (IBAction)backDown:(UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark -  delegate
#pragma mark

#pragma mark - LXHomeTableViewCellDelegate

#pragma mark -  lazy load

#pragma mark -  memoryWarning

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
